package com.dpwgc.provider.controller;

import com.alibaba.fastjson.JSON;
import com.dpwgc.provider.mapper.DnMapper;
import com.dpwgc.provider.model.Dn;
import com.dpwgc.provider.service.DnService;
import com.dpwgc.provider.utils.DateUtil;
import com.dpwgc.provider.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(value = "/Dn")
public class DnController {

    @Autowired
    DateUtil dateUtil;

    @Autowired
    DnMapper dnMapper;

    @Autowired
    DnService dnService;
    /**
     * 创建代拿订单
     * @param
     * @return
     */
    @RequestMapping(value = "/createDn",method = RequestMethod.POST)
    public ResultUtil<Object> createDn(@RequestParam Map<String,String> params){
        
        Dn dn = JSON.parseObject(JSON.toJSONString(params), Dn.class);
        return dnService.createDnService(dn);
    }

    /**
     * 根据uuid删除代拿订单
     * @param
     * @return
     */
    @RequestMapping(value = "/deleDn",method = RequestMethod.POST)
    public ResultUtil<Object> deleDn(@RequestParam("dnUuid") String dnUuid){

        return dnService.deleDnService(dnUuid);
    }

    /**
     * 根据status与type返回代拿订单列表
     * @param
     * @return
     */
    @RequestMapping(value = "/listDn",method = RequestMethod.POST)
    public ResultUtil<Object> listDn(@RequestParam("dnStatus") int dnStatus,
                                     @RequestParam("dnType") int dnType,
                                     @RequestParam("startPage") Integer startPage,
                                     @RequestParam("endPage") Integer endPage){

        return dnService.listDnService(dnStatus,dnType,startPage,endPage);
    }

    /**
     * 根据用户uuid查找订单
     * @param userUuid
     * @return
     */
    @RequestMapping(value = "/listUserDn",method = RequestMethod.POST)
    public ResultUtil<Object> listUserDn(@RequestParam("userUuid") String userUuid,
                                         @RequestParam("startPage") Integer startPage,
                                         @RequestParam("endPage") Integer endPage){

        return dnService.listUserDnService(userUuid,startPage,endPage);
    }

    /**
     * 根据猎人uuid查找订单
     * @param hunterUuid
     * @return
     */
    @RequestMapping(value = "/listHunterDn",method = RequestMethod.POST)
    public ResultUtil<Object> listHunterDn(@RequestParam("hunterUuid") String hunterUuid,
                                           @RequestParam("startPage") Integer startPage,
                                           @RequestParam("endPage") Integer endPage){

        return dnService.listHunterDnService(hunterUuid,startPage,endPage);
    }

    /**
     * 猎人接受代拿订单
     * @param
     * @return
     */
    @RequestMapping(value = "/acceptDn",method = RequestMethod.POST)
    public ResultUtil<Object> acceptDn(@RequestParam Map<String,String> params){

        return dnService.acceptDnService(params.get("dnUuid"),params.get("hunterUuid"));
    }

    /**
     * 代拿订单完成
     * @param dnUuid 订单uuid
     * @param hunterScore 给猎人评分
     * @return
     */
    @RequestMapping(value = "/finishDn",method = RequestMethod.POST)
    public ResultUtil<Object> finishDn(@RequestParam("dnUuid") String dnUuid,
                                       @RequestParam("hunterScore") int hunterScore){

        return dnService.finishDnService(dnUuid,hunterScore);
    }

    /**
     * 获取订单详细信息
     * @param
     * @return
     */
    @RequestMapping(value = "/getDn",method = RequestMethod.POST)
    public ResultUtil<Object> getDn(@RequestParam("dnUuid") String dnUuid){
        return dnService.getDnService(dnUuid);
    }
}
